var gd_password, gd_id_status, gd_username_status, gd_email_status, gd_phone_status,
    gd_password_status, gd_repassword_status;

//工号校验
$("#gd_id").keyup(function () {
    gd_id_status = false;
    var gd_id = $.trim($("#gd_id").val());
    var reg = /^[A-Za-z0-9]+$/;
    $("#gd_id_checkInfo").css("color", "red");
    if (gd_id.length == 0) {
        $("#gd_id_checkInfo").text("工号不能为空！");
    } else if (!reg.test(gd_id)) {
        $("#gd_id_checkInfo").text("请输入正确的工号！");
    } else if (gd_id.length < 2) {
        $("#gd_id_checkInfo").text("工号过短，不符合要求！");
    } else if (gd_id.length > 12) {
        $("#gd_id_checkInfo").text("工号过长，不符合要求！");
    } else {
        $("#gd_id_checkInfo").css("color", "green");
        $("#gd_id_checkInfo").text("工号可用！");
        gd_id_status = true;
    }
});

//用户名校验
$("#gd_username").keyup(function () {
    gd_username = false;
    var gd_username = $.trim($("#gd_username").val());
    var reg = /^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
    $("#gd_username_checkInfo").css("color", "red");
    if (gd_username.length == 0) {
        $("#gd_username_checkInfo").text("用户名不能为空！");
    } else if (!reg.test(gd_username)) {
        $("#gd_username_checkInfo").text("用户名只能使用汉字、数字、字母、下划线，不能以下划线开头和结尾！");
    } else if (gd_username.length > 16) {
        $("#gd_username_checkInfo").text("用户名过长！");
    } else {
        $("#gd_username_checkInfo").css("color", "green");
        $("#gd_username_checkInfo").text("用户名可用！");
        gd_username_status = true;
    }
});

//邮箱校验
$("#gd_email").keyup(function () {
    gd_email_status = false;
    var gd_email = $.trim($("#gd_email").val());
    var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    $("#gd_email_checkInfo").css("color", "red");
    if (gd_email.length == 0) {
        $("#gd_email_checkInfo").text("邮箱不能为空！");
    } else if (!reg.test(gd_email)) {
        $("#gd_email_checkInfo").text("请输入正确的邮箱地址！");
    } else {
        $("#gd_email_checkInfo").css("color", "green");
        $("#gd_email_checkInfo").text("邮箱可用！");
        gd_email_status = true;
    }
});

//手机号码校验
$("#gd_phone").keyup(function () {
    gd_phone_status = false;
    var gd_phone = $.trim($("#gd_phone").val());
    var reg = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
    $("#gd_phone_checkInfo").css("color", "red");
    if (gd_phone.length == 0) {
        $("#gd_phone_checkInfo").text("手机号码不能为空！");
    } else if (!reg.test(gd_phone)) {
        $("#gd_phone_checkInfo").text("请输入正确的手机号码！");
    } else {
        $("#gd_phone_checkInfo").css("color", "green");
        $("#gd_phone_checkInfo").text("手机号码可用！");
        gd_phone_status = true;
    }
});

//密码校验
$("#gd_password").keyup(function () {
    gd_password_status = false;
    gd_password = $.trim($("#gd_password").val());
    var reg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,14}$/;
    $("#gd_password_checkInfo").css("color", "red");
    if (gd_password.length == 0) {
        $("#gd_password_checkInfo").text("密码不能为空！")
    } else if (!reg.test(gd_password)) {
        $("#gd_password_checkInfo").text("必须包含大小写字母和数字的组合，可以使用特殊字符，长度在6-14之间");
    } else {
        $("#gd_password_checkInfo").css("color", "green");
        $("#gd_password_checkInfo").text("密码可用！");
        gd_password_status = true;
    }
});

//重复密码校验
$("#gd_repassword").keyup(function () {
    gd_repassword_status = false;
    var gd_repassword = $.trim($("#gd_repassword").val());
    $("#gd_repassword_checkInfo").css("color", "red");
    if (gd_repassword.length == 0) {
        $("#gd_repassword_checkInfo").text("再次输入密码不能为空！");
    } else if (!(gd_repassword == gd_password)) {
        $("#gd_repassword_checkInfo").text("密码不一致，请重新输入！");
    } else {
        $("#gd_repassword_checkInfo").css("color", "green");
        $("#gd_repassword_checkInfo").text("密码已确认！");
        gd_repassword_status = true;
    }
});

//表单提交前校验
function chenckFrom() {
    if (gd_id_status && gd_username_status && gd_email_status && gd_password_status && gd_repassword_status && gd_phone_status) {
        return true;
    } else {
        return false;
    }
}


